{// 引入标签库 }
<tagLib name="html" />
<include file="Public:header" />
<load href='__TMPL__Common/js/jquery.bgiframe.js' />
<load href='__TMPL__Common/js/jquery.weebox.js' />
<load href='__TMPL__Common/style/weebox.css' />

<script type="text/javascript">
	function show_detail(id)
	{
		window.location.href=ROOT+'?m=Deal&a=show_detail&id='+id;
	}
	function preview(id)
	{
		window.open("__ROOT__/index.php?ctl=deal&id="+id+"&preview=1");
	}
	function repay_plan(id)
	{
		window.location.href=ROOT+'?m=Deal&a=repay_plan&id='+id;
	}
	

</script>
<php>
	function a_get_deal_type($type,$id)
	{
		$deal = M("Deal")->getById($id);
		if($deal['is_coupon'])
		return l("COUNT_TYPE_".$deal['deal_type']);
		else
		return l("NO_DEAL_COUPON_GEN");
		
	}
	
	function a_get_buy_status($buy_status,$deal)
	{
		if($deal['is_effect'] == 0){
			return l("IS_EFFECT_0");
		}
		if($buy_status==2){
			return "<span style='color:red'>".l("DEAL_STATUS_".$buy_status)."</span>";
		}
		else{
			if($deal['deal_status'] == 1 && ($deal['start_time'] + $deal['enddate'] *24*3600 - 1) < TIME_UTC){
				return l("DEAL_STATUS_3");
			}
			else
				return l("DEAL_STATUS_".$buy_status);
		}
	}
	function get_buy_type_title($buy_type)
	{
		return l("DEAL_BUY_TYPE_".$buy_type);
	}
	
	function get_is_has_loans($is_has_loans,$deal){
		if($deal['deal_status'] >= 4 || $deal['deal_status'] == 2){
			if($is_has_loans==0){
				return '<a href="javascript:show_detail('.$deal['id'].')" style="color:red">未放款</a>';
			}
			else{
				return "<span style='color:red'>已放款</span>";
			}
		}
		else
		{
			return "未放款";
		}
	}
	function get_is_has_received($is_has_received,$deal){
		if($deal['deal_status']==3 || $deal['deal_status'] == 2  || ((($deal['start_time'] + $deal['end_date'] *24*3600 - 1) < TIME_UTC) && $deal['deal_status'] == 1) || $deal['deal_status'] == 1){
			if($is_has_received==0 && ($deal['deal_status'] == 2 || ((($deal['start_time'] + $deal['end_date'] *24*3600 - 1) < TIME_UTC) && $deal['deal_status'] == 1))){
				if($deal['deal_status'] == 1)
					return '<a href="javascript:show_detail('.$deal['id'].')" style="color:red">未满标</a>';
				else
					return '<a href="javascript:show_detail('.$deal['id'].')" style="color:red">'.($deal['buy_count'] > 0 ? "未返还" : "未返还").'</a>';
			}
			else{
				if($deal['buy_count'] > 0){
					if($deal['is_has_received']==0){
						return '<a href="javascript:show_detail('.$deal['id'].')" style="color:red">未返还</a>';
					}
					else{
						return "<span style='color:red'>已返还</span>";
					}
				}
				else
					return "未返还";
			}
		}
		else{
			return "未返还";
		}
	}
	
	function get_ips_status($s,$deal){
		if(app_conf("OPEN_IPS") == 0){
			return "未开启功能";
		}
		$msg = "";
		if($deal['mer_bill_no'] == ""){
			if($deal['deal_status']>=3 || $deal['deal_status']==2 || $deal['buy_count'] >0){
				$msg .="借款:无法同步<br>";
			}
			else{
				$msg .='借款:<a href="__ROOT__/index.php?ctl=collocation&act=RegisterSubject&pOperationType=1&deal_id='.$deal['id'].'" target="_blank">同步</a><br>';
			}
		}
		else{
			$msg .="借款:已同步<br>";
		}
		if($deal['mer_bill_no'] != "" && $deal['agency_id'] > 0){
			if($deal['ips_guarantor_bill_no'] == ""){
				if($deal['deal_status']>=3 || $deal['deal_status']==2 || $deal['buy_count'] >0){
					$msg .="&nbsp;担保:无法同步";
				}
				else{
					$msg .='&nbsp;担保:<a href="__ROOT__/index.php?ctl=collocation&act=RegisterGuarantor&deal_id='.$deal['id'].'" target="_blank">同步</a>';
				}
			}
			else{
				$msg .="&nbsp;担保:已同步<br>";
			}
		}
		
		if($deal['deal_status'] == 5  && $deal['ips_over'] == 0 && $deal['ips_bill_no'] != ""){
			$msg .='&nbsp;<a href="__ROOT__/index.php?ctl=collocation&act=RegisterSubject&pOperationType=2&status=1&deal_id='.$deal['id'].'" target="_blank">还款完成</a>';
		}
		
		return $msg;
	}
</php>
<div class="main">
<div class="main_title">{$main_title}</div>
<div class="blank5"></div>
<div class="button_row">
	<input type="button" class="button" value="{%ADD}" onclick="add();" />
	<input type="button" class="button" value="{%DEL}" onclick="del();" />
</div>
<div class="blank5"></div>
<div class="search_row">
	<form name="search" action="__APP__" method="get">	
		{%DEAL_NAME}：<input type="text" class="textbox" name="name" value="{:trim($_REQUEST['name'])}" />
		
		{%CATE_TREE}：
		<select name="cate_id">
			<option value="0" <if condition="intval($_REQUEST['cate_id']) eq 0">selected="selected"</if>>{%NO_SELECT_CATE}</option>
			<foreach name="cate_tree" item="cate_item">
				<option value="{$cate_item.id}" <if condition="intval($_REQUEST['cate_id']) eq $cate_item['id']">selected="selected"</if>>{$cate_item.title_show}</option>
			</foreach>
		</select>
		贷款人：
		<input type="text" class="textbox" name="user_name" value="{:trim($_REQUEST['user_name'])}" size="10" />
		贷款状态
		<select name="deal_status">
			<option value="all" <if condition="$_REQUEST['deal_status'] eq 'all' || trim($_REQUEST['deal_status']) eq ''">selected="selected"</if>>所有状态</option>
			<option value="0" <if condition="$_REQUEST['deal_status'] neq 'all' && trim($_REQUEST['deal_status']) neq '' && intval($_REQUEST['deal_status']) eq 0">selected="selected"</if>>{%DEAL_STATUS_0}</option>
			<option value="1" <if condition="intval($_REQUEST['deal_status']) eq 1">selected="selected"</if>>{%DEAL_STATUS_1}</option>
			<option value="2" <if condition="intval($_REQUEST['deal_status']) eq 2">selected="selected"</if>>{%DEAL_STATUS_2}</option>
			<option value="3" <if condition="intval($_REQUEST['deal_status']) eq 3">selected="selected"</if>>{%DEAL_STATUS_3}</option>
			<option value="4" <if condition="intval($_REQUEST['deal_status']) eq 4">selected="selected"</if>>{%DEAL_STATUS_4}</option>
			<option value="5" <if condition="intval($_REQUEST['deal_status']) eq 5">selected="selected"</if>>{%DEAL_STATUS_5}</option>
		</select>
		满标放款：
		<select name="is_has_loans">
			<option value="all" <if condition="$_REQUEST['is_has_loans'] eq 'all' || trim($_REQUEST['is_has_loans']) eq ''">selected="selected"</if>>全部</option>
			<option value="0" <if condition="$_REQUEST['is_has_loans'] neq 'all' && trim($_REQUEST['is_has_loans']) neq '' && intval($_REQUEST['is_has_loans']) eq 0">selected="selected"</if>>未放款</option>
			<option value="1" <if condition="intval($_REQUEST['is_has_loans']) eq 1">selected="selected"</if>>已放款</option>
		</select>
		
		
		流标返还
		<select name="is_has_received">
			<option value="all" <if condition="$_REQUEST['is_has_received'] eq 'all' || trim($_REQUEST['is_has_received']) eq ''">selected="selected"</if>>全部</option>
			<option value="0" <if condition="$_REQUEST['is_has_received'] neq 'all' && trim($_REQUEST['is_has_received']) neq '' && intval($_REQUEST['is_has_received']) eq 0">selected="selected"</if>>未返还</option>
			<option value="1" <if condition="intval($_REQUEST['is_has_received']) eq 1">selected="selected"</if>>已返还</option>
		</select>
		<input type="hidden" value="Deal" name="m" />
		<input type="hidden" value="index" name="a" />
		<input type="submit" class="button" value="{%SEARCH}" />
	</form>
</div>
<div class="blank5"></div>
<html:list 
	id="dataTable" 
	style="dataTable" 
	name="deal" 
	checkbox="true" 
	action="true" 
	datasource="list" 
	show="id:{%ID}|50px
		,name|msubstr:{%DEAL_NAME}:edit
		,cate_id|get_deal_cate_name:{%DEAL_CATE}
		
		,type_id|get_loan_type_name:{%TYPE_TREE}
		,user_id|get_user_name:借款人
		,deal_status|a_get_buy_status=$deal:{%DEAL_STATUS}
		,is_has_loans|get_is_has_loans=$deal:满标放款
		,is_has_received|get_is_has_received=$deal:流标返回
		,is_recommend|get_toogle_status=$deal['id']#is_recommend:{%IS_RECOMMEND}
		,mer_bill_no|get_ips_status=$deal:同步到第三方|100px
		,sort|get_sort=$deal['id']:{%SORT}
		,is_effect|get_is_effect=$deal['id']:{%IS_EFFECT}" 
	actionlist="edit:{%EDIT}, del:{%DEL},repay_plan:还款计划,show_detail:投标详情和操作, preview:{%PREVIEW}"
	actionwidth="200px" /> 

<div class="blank5"></div>
<div class="page">{$page}</div>
</div>
<include file="Public:footer" />